import IScript from "../IScript";
import {user} from "../../types/msg"
import Player from "../../Player";
import ObjContainer from "../../ObjContainer";

export  class S2C_LoginRespScript implements IScript {

    private static  _instance = new S2C_LoginRespScript()
    public static get instance(){
        return S2C_LoginRespScript._instance;
    }
    private constructor(){}

    excute(obj: any) {
        this.handle(obj )
    }

    handle(msg: user.S2C_LoginResp) {
        let own = msg.own
        if(own){
            console.log(`owb[id=${own.id};x=${own.x};y=${own.y}]`);
            
            let player = new Player(own.id as string);
            player.x = own.x as number
            player.y = own.y as number
            ObjContainer.addObj(player)
        }
        if(msg.others && msg.others.length>0){
            msg.others.forEach(other=>{
                console.log(`other[id=${other.id};x=${other.x};y=${other.y}]`);
                
                let player = new Player(other.id as string,false);
                player.x = other.x as number
                player.y = other.y as number
                ObjContainer.addObj(player)
            })

        }
    }
}

export default S2C_LoginRespScript.instance
